package com.lanou.userLogin.category.dao;

import com.lanou.userLogin.category.domain.Category;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CategoryDaoImpl implements CategoryDao {

    private ComboPooledDataSource dataSource = new ComboPooledDataSource();

    @Override
    public List<Category> categoryName() {
        try {
            Connection conn = dataSource.getConnection();
            QueryRunner qr = new QueryRunner();
            List<Category> query = qr.query(conn, "select * from category", new BeanListHandler<Category>(Category.class));
            return query;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return new ArrayList<>();
    }
}
